<template>
  <div id="app">
    <nav>
      <router-link to="/login">Login</router-link> |
      <router-link to="/register">Register</router-link> |
      <router-link to="/index">Index</router-link>
      <span v-if="isLoggedIn"> | <router-link to="/new-post">New Post</router-link></span>
    </nav>
    <router-view />
  </div>
</template>

<script>
export default {
  data() {
    return {
      isLoggedIn: false
    };
  },
  created() {
    this.checkAuthStatus();
    window.addEventListener('storage', this.checkAuthStatus); // 监听 token 变化
  },
  methods: {
    checkAuthStatus() {
      this.isLoggedIn = !!localStorage.getItem('token');
    }
  }
};
</script>
 
<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: #2c3e50;
  margin-top: 60px;
}
</style>